﻿// ==================================================================================================
// Copyright(C) 2018 FI Ltd. All rights reserved.
//
// SYSTEM NAME	: FI.Net Application Framework
// COMPONENT ID	: FI.Core
// COMPONENT DESC:		
//
// CREATED DATE/BY:		18 Aug 2018 / Tian Mi
//
// REVISION HISTORY:	
// DATE/BY			SR#/CS/PM#/OTHERS		DESCRIPTION OF CHANGE
// ==================================================================================================

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace FI.Core.IoC
{
    internal static class Assemblies
    {
        private static Lazy<IEnumerable<Assembly>> assembliesAccessor = new Lazy<IEnumerable<Assembly>>(GetAssembliesCore);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
        private static IEnumerable<Assembly> GetAssembliesCore()
        {
            List<Assembly> assemblies = new List<Assembly>();
            AssemblyName[] icAssemblies = new AssemblyName[]
            {
                new AssemblyName(string.Format("FI.Core, Version={0}, Culture=neutral",Constants.AssembliesVersion)),
                new AssemblyName(string.Format("FI.Core.Wcf, Version={0}, Culture=neutral",Constants.AssembliesVersion)),
                new AssemblyName(string.Format("FI.Core.EntLib, Version={0}, Culture=neutral",Constants.AssembliesVersion)),
                new AssemblyName(string.Format("FI.ExceptionHandling, Version={0}, Culture=neutral",Constants.AssembliesVersion)),
                new AssemblyName(string.Format("FI.Logging, Version={0}, Culture=neutral",Constants.AssembliesVersion)),
                new AssemblyName(string.Format("FI.Messaging, Version={0}, Culture=neutral",Constants.AssembliesVersion)),
                new AssemblyName(string.Format("FI.StringResource, Version={0}, Culture=neutral",Constants.AssembliesVersion))
            };
            foreach (AssemblyName assemblyName in icAssemblies)
            {
                try
                {
                    Assembly assembly = Assembly.Load(assemblyName);
                    assemblies.Add(assembly);
                }
                catch { }
            }
            return assemblies;
        }
        public static IEnumerable<Assembly> GetAssemblies()
        {
            return assembliesAccessor.Value;
        }
    }
}
